package com.erp.erp_ui.ProductLog;

import com.erp.erp_entitys.ProductLog.ProductLogEntity;
import com.erp.erp_entitys.ProductLog.ProductLogExample;
import com.erp.erp_entitys.ProductLog.ProductLogVoEntity;
import com.erp.erp_servers.ProductLog.IProductLogService;
import com.erp.erp_ui.base.Base;
import com.erp.utils.R;
import com.erp.utils.ResultStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName OperationLogControl
 * @Description 产品日志信息
 * @Author songjizhen
 * @Date 2020-06-30 21:41
 * @Version 1.0
 */
@Controller
@RequestMapping(value = "productlog")
public class ProductLogControl extends Base {

    @Autowired
    IProductLogService productLogService;

    /**
     * 根据产品目录获取产品列表
     * @param code
     * @return
     */
    @RequestMapping(value = "selectByPage")
    @ResponseBody
    public R<List<ProductLogVoEntity>> selectByPage(String code){
        try{
            ProductLogExample example=new ProductLogExample();
            ProductLogExample.Criteria criteria = example.createCriteria();
            criteria.andProductCodeEqualTo(code);
            List<ProductLogEntity> productLogEntities = productLogService.selectByExample(example);
            R<List<ProductLogEntity>> build = R.build(productLogEntities);
            List<ProductLogVoEntity> list=new ArrayList<>();
            for(int i=0;i<productLogEntities.size();i++){
                ProductLogVoEntity vo=new ProductLogVoEntity();
                vo=vo.conver(productLogEntities.get(i));
                list.add(vo);
            }
            R<List<ProductLogVoEntity>> build1 = R.build(list);
            build1.setTotal(build.getTotal());
            build1.setCount(build.getCount());
            build1.setCode(build.getCode());
            build1.setMsg(build.getMsg());
            build1.setStatus(build.getStatus());
            return build1;
        }catch (Exception e){
            e.printStackTrace();
            return R.buildError(ResultStatusEnum.ERROR);
        }
    }


}
